package com.backedserver.controller.casemanage;

import com.common.base.BindCreateBy;
import com.common.excel.BaseImportVo;
import com.common.excel.ExcelValueCheckResp;
import com.common.requestvo.casemanage.CaseProblemSituationReqVo;
import com.common.requestvo.casemanage.CaseReqVo;
import com.common.requestvo.departmentjob.JobReqVo;
import com.common.service.casemanage.CaseService;
import com.common.utils.PageUtil;
import com.common.utils.ResultVoUtil;
import com.common.vo.PageVo;
import com.common.vo.ResultVo;
import com.common.vo.casemanage.CaseProblemSituationVo;
import com.common.vo.casemanage.CaseVo;
import com.common.vo.departmentjob.JobVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

/**
 * @author johnny
 * @create 2021-05-19 1:31 下午
 **/
@Api(tags = "案件模块")
@RestController
@RequestMapping("/case")
@Slf4j
public class CaseManagementController {


    private final CaseService caseService;

    public CaseManagementController(CaseService caseService) {
        this.caseService = caseService;
    }


    public static void main(String[] args) {
        String decode = null;
        try {
            decode = URLDecoder.decode("%5B2020%5D32020500048%E5%8F%B7", "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(decode);
    }
    @GetMapping("/listByCondition")
    @ApiOperation(value = "根据条件查询案件列表 (分页)")
    public ResultVo listByCondition(CaseReqVo caseReqVo,
                                    PageVo pageVo) {
        pageVo.setPageNumber(pageVo.getPageNumber() - 1);
        Page<CaseVo> page = caseService.listByCondition(caseReqVo, PageUtil.initPage(pageVo));
        return ResultVoUtil.success(page);
    }

    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除案件信息")
    @ApiImplicitParam(name = "id", value = "案件id", dataType = "Long", example = "1")
    public ResultVo delete(@PathVariable Long id) {
        caseService.delete(id);
        return ResultVoUtil.success();
    }

    /**
     * <p>
     * 根据文件类型，导入内容
     *
     * @param file
     * @return
     * @RequestParam("file") MultipartFile file
     */
    @PostMapping(value = "import")
    @ApiOperation(value = "导入案件信息")
    @BindCreateBy
    public ResultVo importTargetItem(@RequestParam("file") MultipartFile file,
                                     BaseImportVo baseImportVo) {
        baseImportVo.setFile(file);
        ExcelValueCheckResp excelValueCheckResp = caseService.importFile(baseImportVo);
        return ResultVoUtil.success(excelValueCheckResp);
    }





}